using UnityEngine;
using UnityEditor;

using UGUIAnimationOrTween;

[CustomEditor(typeof(UGUIPlayTween))]
public class UGUIPlayTweenEditor : Editor
{
	enum ResetOnPlay
	{
		ContinueFromCurrent,
		RestartTween,
		RestartIfNotPlaying,
	}

	enum SelectedObject
	{
		KeepCurrent,
		SetToNothing,
	}

	public override void OnInspectorGUI ()
	{
		UGUIEditorTools.SetLabelWidth(120f);
		UGUIPlayTween tw = target as UGUIPlayTween;
		GUILayout.Space(6f);

		GUI.changed = false;
		GameObject tt = (GameObject)EditorGUILayout.ObjectField("Tween Target", tw.tweenTarget, typeof(GameObject), true);

		bool inc = EditorGUILayout.Toggle("Include Children", tw.includeChildren);
		int group = EditorGUILayout.IntField("Tween Group", tw.tweenGroup, GUILayout.Width(160f));

		Trigger trigger = (Trigger)EditorGUILayout.EnumPopup("Trigger condition", tw.trigger);
		Direction dir = (Direction)EditorGUILayout.EnumPopup("Play direction", tw.playDirection);
		EnableCondition enab = (EnableCondition)EditorGUILayout.EnumPopup("If target is disabled", tw.ifDisabledOnPlay);
		ResetOnPlay rs = tw.resetOnPlay ? ResetOnPlay.RestartTween : (tw.resetIfDisabled ? ResetOnPlay.RestartIfNotPlaying : ResetOnPlay.ContinueFromCurrent);
		ResetOnPlay reset = (ResetOnPlay)EditorGUILayout.EnumPopup("On activation", rs);
		DisableCondition dis = (DisableCondition)EditorGUILayout.EnumPopup("When finished", tw.disableWhenFinished);

		if (GUI.changed)
		{
			UGUIEditorTools.RegisterUndo("Tween Change", tw);
			tw.tweenTarget = tt;
			tw.tweenGroup = group;
			tw.includeChildren = inc;
			tw.trigger = trigger;
			tw.playDirection = dir;
			tw.ifDisabledOnPlay = enab;
			tw.resetOnPlay = (reset == ResetOnPlay.RestartTween);
			tw.resetIfDisabled = (reset == ResetOnPlay.RestartIfNotPlaying);
			tw.disableWhenFinished = dis;
			UGUITools.SetDirty(tw);
		}

		UGUIEditorTools.SetLabelWidth(80f);
		UGUIEditorTools.DrawEvents("On Finished", tw, tw.onFinished);
	}
}
